import socket,sys,traceback,select

host = 'localhost'
port = 51423

spinsize = 10
spinpos = 0
spindir = 1

def spin():
	global spinsize,spinpos,spindir

	spinstr  = '.' * spinpos + \
	       '|' + '.'* (spinsize - spinpos - 1)
	sys.stdout.write('\r' + spintstr + '')
	sys.stdin.flush()

	spinpos += spindir
	if spinpos < 0:
		spindir = 1
		spinpos = 1
	
    	elif spinpos >= spinsize :
		spinpos -= 2
		spindir = -1

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))

p  = select.poll()
p.register(s.fileno(),select.POLLIN | select.POLLERR | select.POLLHUP)

while True :
	results = p.poll(50)
    	if len (results):
	    if results[0][1] == select.POLLIN:
	    	data = s.recv(4096)
	    	if not len(data):
		    print "\n Remote end closed connection ; exiting."
		    break
		sys.stdout.write("recv > " +data)
		sys.stdin.flush()
	else :
	    print "\n remote error ; exiting"
	    sys.exit(0)
spin()

